﻿Public Class Form3GongWeiOut
    Public usr As String
    Dim objGtProcedureResultDetails As New clsGtProcedureResultDetails
    Dim objGtNgReasonDetails As New clsGtNgReasonDetails
    Dim dt As DataTable
    Private Sub Form3GongWeiOut_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        setData()
        setDgvData()
    End Sub

    Public Sub setData()
        dt = objGtProcedureResultDetails.getGtProcedureResultDetailsList("2")
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        dgvOper.AutoGenerateColumns = False
        dgvOper.DataSource = dt
    End Sub

    Public Sub setDgvData()
        dt = objGtNgReasonDetails.getGtNgDetailsList("1", "2")
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        dgvNg.AutoGenerateColumns = False
        dgvNg.DataSource = dt
    End Sub

    Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
        If dgvOper.SelectedRows.Count > 0 Then
            If dgvOper.SelectedRows(0).Cells("validity").Value.ToString().Equals("0") Then
                If MsgBox("确认全部合格吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgvOper.SelectedRows(0).Cells("Col_sys_id").Value.ToString()
                    Dim procedure_no As String = dgvOper.SelectedRows(0).Cells("Col_procedure_no").Value.ToString()
                    Dim b_gt_sys_id As String = dgvOper.SelectedRows(0).Cells("Colb_gt_sys_id").Value.ToString()
                    Dim ng_num As String = dgvOper.SelectedRows(0).Cells("Col_ng_num").Value.ToString()
                    'Dim rtn As Integer = objGtNgDetails.updateValidity(sys_id, procedure_no, b_gt_sys_id, ng_num, oper_u)
                    'If rtn <> -2 Then
                    '    MsgBox("作废成功")
                    '    setDgvData()
                    'Else
                    '    MsgBox("作废失败")
                    'End If
                End If
            Else
                MsgBox("该记录已作废")
            End If
        End If
    End Sub

    Private Sub btnNg_Click(sender As Object, e As EventArgs) Handles btnNg.Click
        If dgvOper.SelectedRows.Count > 0 Then
            Dim formNgOper As New FormNgOper()
            'formNgOper.usr = usr
            formNgOper.ShowDialog(Me)
        End If
    End Sub

    Private Sub btnValidityOper_Click(sender As Object, e As EventArgs) Handles btnValidityOper.Click
        If dgvOper.SelectedRows.Count > 0 Then
            If dgvOper.SelectedRows(0).Cells("validity").Value.ToString().Equals("1") Then
                If MsgBox("确认要进行作废吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgvOper.SelectedRows(0).Cells("Col_sys_id").Value.ToString()
                    Dim procedure_no As String = dgvOper.SelectedRows(0).Cells("Col_procedure_no").Value.ToString()
                    Dim b_gt_sys_id As String = dgvOper.SelectedRows(0).Cells("Colb_gt_sys_id").Value.ToString()
                    Dim ng_num As String = dgvOper.SelectedRows(0).Cells("Col_ng_num").Value.ToString()
                    'Dim rtn As Integer = objGtNgDetails.updateValidity(sys_id, procedure_no, b_gt_sys_id, ng_num, oper_u)
                    'If rtn <> -2 Then
                    '    MsgBox("作废成功")
                    '    setDgvData()
                    'Else
                    '    MsgBox("作废失败")
                    'End If
                End If
            Else
                MsgBox("该记录已作废")
            End If
        End If
    End Sub

    Private Sub btnValidity_Click(sender As Object, e As EventArgs) Handles btnValidity.Click
        If dgvNg.SelectedRows.Count > 0 Then
            If dgvNg.SelectedRows(0).Cells("validity").Value.ToString().Equals("1") Then
                If MsgBox("确认要进行作废吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgvNg.SelectedRows(0).Cells("Col_sys_id").Value.ToString()
                    Dim procedure_no As String = dgvNg.SelectedRows(0).Cells("Col_procedure_no").Value.ToString()
                    Dim b_gt_sys_id As String = dgvNg.SelectedRows(0).Cells("Colb_gt_sys_id").Value.ToString()
                    Dim ng_num As String = dgvNg.SelectedRows(0).Cells("Col_ng_num").Value.ToString()
                    'Dim rtn As Integer = objGtNgDetails.updateValidity(sys_id, procedure_no, b_gt_sys_id, ng_num, oper_u)
                    'If rtn <> -2 Then
                    '    MsgBox("作废成功")
                    '    setDgvData()
                    'Else
                    '    MsgBox("作废失败")
                    'End If
                End If
            Else
                MsgBox("该记录已作废")
            End If
        End If
    End Sub
End Class